﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using DevExpress.XtraReports.UI;
using BHair.bb;

namespace BHair
{
    public partial class frmkcbb : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmkcbb()
        {
            InitializeComponent();
        }

        private void frmkcbb_Load(object sender, EventArgs e)
        {
            selectall();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        public DataSet selectall() 
        {
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(constr);
            DataTable dt = new DataTable();
            string sql2 = "SELECT [iid],[iname],[ifprice],[iamount],[ireadme] FROM [BHairDB].[dbo].[items] where jc!=1 and jc!=2";
            try
            {
                conn.Open();
                string sql1 = "SELECT [iid] as 商品编号,[iname] as 商品名称,[iamount] as 库存数量,[ireadme] as 商品说明 FROM [BHairDB].[dbo].[items] where jc!=1 and jc!=2";
                SqlDataAdapter sda = new SqlDataAdapter(sql1, conn);
                sda.Fill(dt);
                this.dataGridView1.DataSource = dt;
                SqlDataAdapter sda1 = new SqlDataAdapter(sql2,conn);
                sda1.Fill(ds, "items");
                
                conn.Close();
            }
            catch (Exception ex) 
            {
                MessageBox.Show(ex.Message);
            }
            return ds;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != string.Empty)
            {
                XtraReportkcbb kcbb = new XtraReportkcbb(select());
                kcbb.ShowPreview();
               
            }
            else
            {
                XtraReportkcbb kcbb = new XtraReportkcbb(selectall());
                kcbb.ShowPreview();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = selectall();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            select();
        }
        public DataSet select()
        {
            DataSet ds = new DataSet();
            SqlConnection conn = new SqlConnection(constr);
            DataTable dt = new DataTable();
            string sql2 =string.Format( "SELECT [iid],[iname],[ifprice],[iamount],[ireadme] FROM [BHairDB].[dbo].[items] where jc!=1 and jc!=2 and iname like '%{0}%'",textBox1.Text);
            try
            {
                conn.Open();
                string sql1 =string.Format( "SELECT [iid] as 商品编号,[iname] as 商品名称,[iamount] as 库存数量,[ireadme] as 商品说明 FROM [BHairDB].[dbo].[items] where jc!=1 and jc!=2 and iname like '%{0}%'",textBox1.Text);
                SqlDataAdapter sda = new SqlDataAdapter(sql1, conn);
                sda.Fill(dt);
                this.dataGridView1.DataSource = dt;
                SqlDataAdapter sda1 = new SqlDataAdapter(sql2, conn);
                sda1.Fill(ds, "items");

                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return ds;
        }
    }
}
